package com.mgm.conversion.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mgm.conversion.service.ConversionService;
import com.mgm.dao.ConversionInfoMapper;
import com.mgm.pojo.ConversionInfo;
import com.mgm.pojo.ConversionInfoExample;
import com.mgm.pojo.ConversionInfoExample.Criteria;

@Service
public class ConversionServiceImpl implements ConversionService {
	
	@Autowired
	private ConversionInfoMapper conversionInfoMapper;

	@Override
	public int save(ConversionInfo conversionInfo) {
		return conversionInfoMapper.insert(conversionInfo);
	}

	@Override
	public BigDecimal selectTotalCap(String offerid) {
		return conversionInfoMapper.selectTotalCap(offerid);
	}
	
	@Override
	public BigDecimal selectDailyCap(String offerid) {
		return conversionInfoMapper.selectDailyCap(offerid);
	}

	@Override
	public BigDecimal selectTotalCapByAffId(String offerid, String affid) {
		return conversionInfoMapper.selectTotalCapByAffId(offerid, affid);
	}

	@Override
	public BigDecimal selectDailyCapByAffId(String offerid, String affid) {
		return conversionInfoMapper.selectDailyCapByAffId(offerid, affid);
	}

	@Override
	public long countByCode(String offerid, String affid, String code) {
		ConversionInfoExample example = new ConversionInfoExample();
		Criteria criteria = example.createCriteria();
		criteria.andOfferidEqualTo(offerid);
		criteria.andAffidEqualTo(affid);
		criteria.andCodeEqualTo(code);
		return conversionInfoMapper.countByExample(example);
	}

	@Override
	public int update(ConversionInfo conversionInfo) {
		int updateByPrimaryKey = conversionInfoMapper.updateByPrimaryKey(conversionInfo);
		return updateByPrimaryKey;
	}

	@Override
	public List<ConversionInfo> findByTid(String tid) {
		ConversionInfoExample example = new ConversionInfoExample();
		Criteria criteria = example.createCriteria();
		criteria.andTidEqualTo(tid);
		return conversionInfoMapper.selectByExample(example);
	}

}
